home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1999 November / SOTMC_Nov1999-Ultimate.iso / mac / REALbasic ƒ / Examples / Applications / FileBrowser#1 / description next >
Encoding:
Text File  |  1998-05-20  |  4.5 KB  |  90 lines  |  [TEXT/R*ch]

  1. FileBrowser:
  2.  
  3. I've been thinking about doing some things with hierarchial list boxes, but i've
  4. found them a bit limited for anything that goes over two levels deep, for several
  5. reasons: 
  6. You need to work to get the display of nested items to look good. 
  7. You can't insert folders, but can only add them to the end of the box. 
  8. You can't code whether the folder is opened or closed when added. 
  9. You can't trigger the open or close events via code.
  10.  
  11. So, i've decided to play around with creating the next best thing - something
  12. that will act something like a hierarchial box in terms of basic display and
  13. functionality.  You can think of double clicking on a folder the equivalent of
  14. opening the disclosure triangle and double clicking the back arrow as the
  15. equivalent of closing it.
  16.  
  17. To provide a demonstration using a hierarchial structure that everybody will
  18. have, i decided to use the file system.  i modeled the window a bit on the Next
  19. Browser, but it is very limited in comparison.  Still, as you could probably tell
  20. by looking at the code, a lot of it is easy to reuse, so it would be simple to
  21. add more listboxes and expand it.  I've also noted where you could add the ability 
  22. to launch non-directories on double clicking.  As an added bonus, i've added drag 
  23. and drop to help anybody who's having trouble with that.
  24.  
  25.  
  26. Practicalities:
  27.  
  28. Both list boxes have a parallel array of folder items.  Both the contents of 
  29. the list boxes and the folder item array are altered within the two methods,
  30. which accept a folder item as their parameter.  This helps keep everything
  31. nicely in synch.
  32.  
  33. The open event of the window loads all the volumes into the first list box.
  34. This is also done when the "Root" button is hit and, finally, when the back
  35. button is hit while in the root of any volume (more on this later).
  36.  
  37. Double clicking ignores a non-directory.  If it is a directory, what happens 
  38. depends on which list box it's in.  In box1, the directory is handed to the
  39. box2 method, which puts its contents in box2.  This happens even if something 
  40. else is already in box2.  If you double click a box2 directory, it hands a 
  41. its parent directory to the box1 method, essentially swapping box2 into box1.
  42. Next, it sends the box2 method the directory, putting its contents there.
  43.  
  44. In addition, the back button is added by the box1 method.  It clears box2, 
  45. gets the parent  of the parent of an item in box1, and sends it to the box1 
  46. method.  If you're in the root level of a volume, though this will throw an 
  47. error  (there's no parent for a volume).  So, in the box1.doubleClick event, 
  48. i added an exception trap.  If this occurs, it simply does the same thing as 
  49. the  "Root" button does (and doesn't add a back arrow).
  50.  
  51. Dropping is accepted on a window-wide basis.  When a folder item is dropped,
  52. everything is cleared and it's handed to box 1.  If the item is a directory,
  53. it's handed to the box1 method.  If not, its parent is.
  54.  
  55. Dragging is quite straightforward from list boxes, since the drag object is
  56. created for you.  The text and folder item properties of the drag item are
  57. populated with from the text in the listbox or the corresponding array item,
  58. respectively.  In box1, a check is thrown in to make sure you don't allow
  59. the user to try to drag the back arrow.
  60.  
  61.  
  62. Implications for general use:
  63.  
  64. Aside from some interesting methods and the use of an exception trap, the most
  65. important thing here is that these methods are very extensible.  As i mentioned
  66. above, it would be very easy to expand this to multiple listboxes by slightly 
  67. altering the methods.  In fact, the methods for any listboxes between the first
  68. and last would be identical, allowing for a control array and dynamically created
  69. controls to give this a great deal of flexibility.  In the other direction, you
  70. could easily hand a directory double clicked in box1 to its own method, opening
  71. it up in the same listbox.  This would allow for custom open/save type dialogs.
  72. By querying the .type property, you could add custom icons for files, applications,
  73. etc.
  74.  
  75. In addition, you can make your own objects which will fit into these methods with
  76. little modification.  Just make sure your objects have the following properties:
  77. name as string
  78. count as integer
  79. directory as boolean
  80. item (0) as yourObject
  81. After that, change the arrays to containing yourObject and the two methods to
  82. accpeting yourObject as a parameter and you're in business.
  83.  
  84.  
  85. Enjoy!
  86. Jay Timmer
  87. jtimmer@tuna.net
  88. For personal use, this code is free.  If you use the code in any commercial 
  89. programs, i get a license for a copy.
  90.